# 开发时间 2023/6/17 9:40
import sys
from tkinter import *
import main.HomeWindowBtnEnt as HomeWindowBtnEnt


def home_window(authority):
    """

    @param authority: 登录者查看权限
    @return:
    """
    home_window_root = Tk()
    home_window_root.title('学生管理系统')
    home_window_root.geometry('800x600')
    addBtn1 = Button(home_window_root, text='添加学生', width=30, height=6, activebackground='pink',
                     command=HomeWindowBtnEnt.add_student)
    addBtn1.grid(column=0, row=0, padx=12, pady=12, ipadx=12, ipady=12)
    addCourseBtn1 = Button(home_window_root, text='添加课程', width=30, height=6, activebackground='pink',
                           command=HomeWindowBtnEnt.add_course)
    addCourseBtn1.grid(column=1, row=0, padx=12, pady=12, ipadx=12, ipady=12)
    addCourseBtn2 = Button(home_window_root, text='添加课时', width=30, height=6, activebackground='pink',
                           command=HomeWindowBtnEnt.add_course_association)
    addCourseBtn2.grid(column=2, row=0, padx=12, pady=12, ipadx=12, ipady=12)
    showLBtn1 = Button(home_window_root, text='LEGO学生', width=30, height=6, activebackground='red',
                       command=lambda: HomeWindowBtnEnt.search_students(0))
    showLBtn1.grid(column=0, row=1, padx=12, pady=12, ipadx=12, ipady=12)
    showWBtn1 = Button(home_window_root, text='WEDO学生', width=30, height=6, activebackground='green',
                       command=lambda: HomeWindowBtnEnt.search_students(1))
    showWBtn1.grid(column=1, row=1, padx=12, pady=12, ipadx=12, ipady=12)
    showSBtn1 = Button(home_window_root, text='SCRATCH学生', width=30, height=6, activebackground='yellow',
                       command=lambda: HomeWindowBtnEnt.search_students(2))
    showSBtn1.grid(column=2, row=1, padx=12, pady=12, ipadx=12, ipady=12)
    showPBtn1 = Button(home_window_root, text='PYTHON学生', width=30, height=6, activebackground='blue',
                       command=lambda: HomeWindowBtnEnt.search_students(3))
    showPBtn1.grid(column=0, row=2, padx=12, pady=12, ipadx=12, ipady=12)

    if authority == 0:
        showTeachersBtn = Button(home_window_root, text='老师信息', width=30, height=6, activebackground='blue',
                                 command=HomeWindowBtnEnt.search_teachers)
        showTeachersBtn.grid(column=1, row=2, padx=12, pady=12, ipadx=12, ipady=12)

    exitBtn1 = Button(home_window_root, text='退出登录', width=30, height=6, activebackground='blue',
                      command=lambda: HomeWindowBtnEnt.exit_login(home_window_root))
    exitBtn1.grid(column=2, row=2, padx=12, pady=12, ipadx=12, ipady=12)

    def _quit():
        # 销毁root窗口
        home_window_root.destroy()
        sys.exit(0)
        # 在此处下方可以写入结束线程的语句，如果开启了多线程的话。

    home_window_root.protocol("WM_DELETE_WINDOW", _quit)
    home_window_root.mainloop()
